// Functions associated with the Button class
//-----------------

//-----------------
// Includes libraries and other files
#include "Button.h"
//-----------------

//-----------------
//// CONSTRUCTOR - Button
Button::Button()
	: text_( ""), rect_x_pos_( 0), rect_y_pos_( 0), rect_width_( 0), rect_height_( 0), colour_alpha_( 0), colour_red_( 0), colour_green_( 0), colour_blue_( 0)
{}

//// CONSTRUCTOR - Button
Button::Button( const std::string& t, const int& x, const int& y, const int& a, const int& r, const int& g, const int& b) {
	set_button( t, x, y, a, r, g, b);
}

//// DESTRUCTOR - Button
Button::~Button() 
{}
//-----------------

//-----------------
//// FUNCTION - mouseover
// return true if the mouse is currently on top of the button
bool Button::mouseover( const int& x, const int& y, const int& h) const {
	// Pre-conditions :- none
	assert( true);

	int x_left( 0), x_right( 0), y_bottom( 0), y_top( 0);

	// The anchor point of the bounding box is the top left.
	// The y co-ordinates of the box must be flipped as the text works from the top-left of the window
	// while DirectX input works from the bottom left.
	// For some reason, the boxes are off-set upwards by an amount equal to just over their height,
	// and thus, box_y has its height subtracted from it as well as box_yy (so it's done twice).
	x_left		=   get_x_pos();
	x_right		=   x_left + get_rect_width();

	y_bottom	= ((get_y_pos() - h) * -1);
	y_top		=   y_bottom - get_rect_height();

	// if the mouse (i.e. the parameters) is within the button's bounding box, then return true
	if(( x >= x_left) && (x <= x_right) && ( y <= y_bottom) && ( y >= y_top))
		return true;
	else
		return false;
}

//// FUNCTION - get_text_length
// return the length of the text associated with the Button
int Button::get_text_length() const {
	// Pre-conditions :- none
	assert( true);

	return text_.length();
}

//// FUNCTION - get_text
// return the button's text
std::string Button::get_text() const {
	// Pre-conditions :- none
	assert( true);

	return text_;
}

//// FUNCTION - get_x_pos
// return the x coordinate of the text box
int Button::get_x_pos() const {
	// Pre-conditions :- none
	assert( true);

	return rect_x_pos_;
}

//// FUNCTION - get_y_pos
// return the y coordinate of the text box
int Button::get_y_pos() const {
	// Pre-conditions :- none
	assert( true);

	return rect_y_pos_;
}

//// FUNCTION - get_rect_width
// return the width of the text box
int Button::get_rect_width() const {
	// Pre-conditions :- none
	assert( true);

	return rect_width_;
}

//// FUNCTION - get_rect_height
// return the height of the text box
int Button::get_rect_height() const {
	// Pre-conditions :- none
	assert( true);

	return rect_height_;
}

//// FUNCTION - get_colour_alpha
// return the alpha of the text
int Button::get_colour_alpha() const {
	// Pre-conditions :- none
	assert( true);

	return colour_alpha_;
}

//// FUNCTION - get_colour_red
// return the value of red of the text colour
int Button::get_colour_red() const {
	// Pre-conditions :- none
	assert( true);

	return colour_red_;
}

//// FUNCTION - get_colour_green
// return the value of green of the text colour
int Button::get_colour_green() const {
	// Pre-conditions :- none
	assert( true);

	return colour_green_;
}

//// FUNCTION - get_colour_blue
// return the value of blue of the text colour
int Button::get_colour_blue() const {
	// Pre-conditions :- none
	assert( true);

	return colour_blue_;
}

//// FUNCTION - set_button
// sets the information for the button
void Button::set_button( const std::string& t, const int& x, const int& y, const int& a, const int& r, const int& g, const int& b) {
	// Pre-conditions :- none
	assert( true);

	// set the text that's displayed by the button
	text_ = t;

	// set the size of the text's bounding box (if the box is too small then the text will be clipped)
	rect_x_pos_		= x;
	rect_y_pos_		= y;
	rect_width_		= t.length()*CHAR_WIDTH;
	rect_height_	= 20;

	// set the colour of the text
	colour_alpha_	= a;
	colour_red_		= r;
	colour_green_	= g;
	colour_blue_	= b;
}